//
//  BestNewCell.m
//  Korea
//
//  Created by 崔剑 on 15/8/25.
//  Copyright (c) 2015年 KoreaGo. All rights reserved.
//

#import "BestNewCell.h"
#import "NewInfoViewController.h"
#import "UIColor+RGBColor.h"
#import "Header.h"
#import <ShareSDK/ShareSDK.h>
#import "Recommend.h"
#import "UMSocial.h"
@implementation BestNewCell

- (void)setRecommend:(Recommend *)recommend
{
    _recommend = recommend;
    
    _introduceLabel.text = recommend.sellPoint;
    
    [_bestNewImage sd_setImageWithURL:[NSURL URLWithString:recommend.image]];
    
    }


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        // cell背景颜色
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.bestNewImage = [[UIImageView alloc] init];
        self.bestNewImage.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:self.bestNewImage];
        
        self.introduceLabel = [[UILabel alloc] init];
        self.introduceLabel.numberOfLines = 3;
        self.introduceLabel.textColor = [UIColor colorWithRGB:0x515151 alpha:1];
        self.introduceLabel.font = [UIFont boldSystemFontOfSize:14];
        [self.contentView addSubview:self.introduceLabel];
        
        self.shareLabel = [[UILabel alloc] init];
        self.shareLabel.textColor = [UIColor colorWithRGB:0x929292 alpha:1];
        self.shareLabel.userInteractionEnabled = YES;
        self.shareLabel.tag = 10001;
        self.shareLabel.text = @"   分享";
        // 添加点击事件
        UITapGestureRecognizer *shareTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(shareTouchUpInside:)];
        [self.shareLabel addGestureRecognizer:shareTapGestureRecognizer];
        self.shareLabel.textAlignment = NSTextAlignmentCenter;
        self.shareLabel.font = [UIFont boldSystemFontOfSize:14];
        [self.contentView addSubview:self.shareLabel];
        
        self.commentLabel = [[UILabel alloc] init];
        self.commentLabel.textColor = [UIColor colorWithRGB:0x929292 alpha:1];
        self.commentLabel.userInteractionEnabled = YES;
        self.commentLabel.tag = 10002;
        self.commentLabel.text = @"   评论";
//        UITapGestureRecognizer *commentTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(commentTouchUpInside:)];
//        [self.commentLabel addGestureRecognizer:commentTapGestureRecognizer];
        self.commentLabel.textAlignment = NSTextAlignmentCenter;
        self.commentLabel.font = [UIFont boldSystemFontOfSize:14];
        [self.contentView addSubview:self.commentLabel];
        
        self.praiseLabel = [[UILabel alloc] init];
        self.praiseLabel.textColor = [UIColor colorWithRGB:0x929292 alpha:1];
        self.praiseLabel.userInteractionEnabled = YES;
        self.praiseLabel.tag = 10003;
        self.praiseLabel.text = @"  赞";
        UITapGestureRecognizer *praiseTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(praiseTouchUpInside:)];
        [self.praiseLabel addGestureRecognizer:praiseTapGestureRecognizer];
        self.praiseLabel.textAlignment = NSTextAlignmentCenter;
        self.praiseLabel.font = [UIFont boldSystemFontOfSize:14];
        [self.contentView addSubview:self.praiseLabel];
        
        self.shareIV = [[UIImageView alloc] init];
        [self.shareIV setImage:[UIImage imageNamed:@"share@2x.png"]];
        [self.shareLabel addSubview:self.shareIV];
        self.commentIV = [[UIImageView alloc] init];
        [self.commentIV setImage:[UIImage imageNamed:@"comment@2x.png"]];
        [self.commentLabel addSubview:self.commentIV];
        
        self.praiseIV = [[UIImageView alloc] init];
        [self.praiseIV setImage:[UIImage imageNamed:@"like@2x.png"]];
        [self.praiseLabel addSubview:self.praiseIV];
        
        self.verticalViewOne = [[UIView alloc] init];
        self.verticalViewOne.backgroundColor = [UIColor colorWithRGB:0xc8c7cc alpha:1];
        [self.contentView addSubview:self.verticalViewOne];
        
        self.verticalViewTwo = [[UIView alloc] init];
        self.verticalViewTwo.backgroundColor = [UIColor colorWithRGB:0xc8c7cc alpha:1];
        [self.contentView addSubview:self.verticalViewTwo];

        self.horizontalView = [[UIView alloc] init];
        self.horizontalView.backgroundColor = [UIColor colorWithRGB:0xc8c7cc alpha:1];
        [self.contentView addSubview:self.horizontalView];

    }
    
    return self;
    
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat width = self.contentView.frame.size.width;
    CGFloat height = self.contentView.frame.size.height;
    CGFloat unit = (height - width) / 3;
    CGFloat buttonExtent = (width - 2) / 3;
    
    self.bestNewImage.frame = CGRectMake(0, 0, width, width);
    self.introduceLabel.frame = CGRectMake(0, width, width, unit * 2);
    self.shareLabel.frame = CGRectMake(0, width + unit * 2 + 1, buttonExtent, unit);
    self.commentLabel.frame = CGRectMake(1 + buttonExtent, width + unit * 2 + 1, buttonExtent, unit);
    self.praiseLabel.frame = CGRectMake(buttonExtent * 2 + 2, width + unit * 2 + 1, buttonExtent, unit);
    self.shareIV.frame = CGRectMake(buttonExtent / 4, unit / 5, buttonExtent / 6, unit / 5 * 3);
    self.commentIV.frame = CGRectMake(buttonExtent / 4, unit / 5, buttonExtent / 6, unit / 5 * 3);
    self.praiseIV.frame = CGRectMake(buttonExtent / 4, unit / 5, buttonExtent / 6, unit / 5 * 3);
    self.verticalViewOne.frame = CGRectMake(buttonExtent, width + unit * 2 + 1 + unit / 4, 1, unit / 2);
    self.verticalViewTwo.frame = CGRectMake(buttonExtent * 2 + 1, width + unit * 2 + 1 + unit / 4 * 1, 1, unit / 2);
    self.horizontalView.frame = CGRectMake(0, width + unit * 2, width, 1);
}


- (void)shareTouchUpInside:(UITapGestureRecognizer *)recognizer
{
//    NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ShareSDK" ofType:@"png"];
//    
//    //构造分享内容
//    id<ISSContent> publishContent = [ShareSDK content:@"分享内容"
//                                       defaultContent:@"测试一下"
//                                                image:[ShareSDK imageWithPath:imagePath]
//                                                title:@"ShareSDK"
//                                                  url:@"http://www.mob.com"
//                                          description:@"这是一条测试信息"
//                                            mediaType:SSPublishContentMediaTypeNews];
//    //创建弹出菜单容器
//    id<ISSContainer> container = [ShareSDK container];
////    [container setIPadContainerWithView:sender arrowDirect:UIPopoverArrowDirectionUp];
//    
//    //弹出分享菜单
//    [ShareSDK showShareActionSheet:container
//                         shareList:nil
//                           content:publishContent
//                     statusBarTips:YES
//                       authOptions:nil
//                      shareOptions:nil
//                            result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
//                                
//                                if (state == SSResponseStateSuccess)
//                                {
//                                    NSLog(@"分享成功");
//                                }
//                                else if (state == SSResponseStateFail)
//                                {
//                                    NSLog(@"分享失败,错误码:%ld,错误描述:%@", [error errorCode], [error errorDescription]);
//                                }
//                            }];
//    [UMSocialSnsService presentSnsIconSheetView:self.window
//                                         appKey:@"507fcab25270157b37000010"
//                                      shareText:@"你要分享的文字"
//                                     shareImage:[UIImage imageNamed:@"icon.png"]
//                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,nil]
//                                       delegate:self];
}

//- (void)commentTouchUpInside:(UITapGestureRecognizer *)recognizer
//{
//    NSLog(@"点击评论");
//    
//}

- (void)praiseTouchUpInside:(UITapGestureRecognizer *)recognizer
{
    
    
    NSLog(@"点击点赞");
    if (self.likeFlag == NO) {
        
        [self.praiseIV setImage:[UIImage imageNamed:@"like2@2x.png"]];
        self.praiseLabel.textColor = [UIColor colorWithRGB:0xfe868f alpha:YES];
        self.likeFlag =! self.likeFlag;
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeColor" object:@"praise2@2x.png" userInfo:nil];

    } else {
        
        [self.praiseIV setImage:[UIImage imageNamed:@"like@2x.png"]];
        self.praiseLabel.textColor = [UIColor colorWithRGB:0x929292 alpha:YES];
        self.likeFlag =! self.likeFlag;
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeColor" object:@"praise@2x.png" userInfo:nil];

    }
    
    
    
    
    
    
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
